package com.hmdp.config;

import com.hmdp.interceptor.LoginInterceptor;
import com.hmdp.interceptor.RefershTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/5/27 10:05
 * @Description：注册拦截器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LoginInterceptor loginInterceptor=new LoginInterceptor();
        List<String> list=new ArrayList<>();
        list.add("/shop/**");
        list.add("/voucher/**");
        list.add("/shop-type/**");
        list.add("/upload/**");
        list.add("/blog/hot");
        list.add("/user/code");
        list.add("/user/login");
        registry.addInterceptor(loginInterceptor).excludePathPatterns(list).order(1);
        RefershTokenInterceptor refershTokenInterceptor=new RefershTokenInterceptor(stringRedisTemplate);
      // addPathPatterns("/**"); 拦截所有  order(0)>order(1)确保下面的拦截器优先执行
      registry.addInterceptor(refershTokenInterceptor).addPathPatterns("/**").order(0);
    }
}
